
public class InferenceRule {
  private FuzzySet [][] rules;

  public InferenceRule() {
    rules = new FuzzySet[5][5];

    rules[FuzzySet.D_VERYFAR.ordinal()]  [FuzzySet.V_VERYSLOW.ordinal()-5]  = FuzzySet.A_ACCELERATEHARD;
  
    rules[FuzzySet.D_VERYFAR.ordinal()]  [FuzzySet.V_SLOW.ordinal()-5]      = FuzzySet.A_ACCELERATE;
    rules[FuzzySet.D_VERYFAR.ordinal()]  [FuzzySet.V_JUSTRIGHT.ordinal()-5] = FuzzySet.A_ACCELERATE;
    rules[FuzzySet.D_FAR.ordinal()]      [FuzzySet.V_VERYSLOW.ordinal()-5]  = FuzzySet.A_ACCELERATE;
    rules[FuzzySet.D_FAR.ordinal()]      [FuzzySet.V_SLOW.ordinal()-5]      = FuzzySet.A_ACCELERATE;
    rules[FuzzySet.D_FAR.ordinal()]      [FuzzySet.V_JUSTRIGHT.ordinal()-5] = FuzzySet.A_ACCELERATE;
    rules[FuzzySet.D_JUSTRIGHT.ordinal()][FuzzySet.V_VERYSLOW.ordinal()-5]  = FuzzySet.A_ACCELERATE;
    rules[FuzzySet.D_JUSTRIGHT.ordinal()][FuzzySet.V_SLOW.ordinal()-5]      = FuzzySet.A_ACCELERATE;

    rules[FuzzySet.D_VERYCLOSE.ordinal()][FuzzySet.V_VERYFAST.ordinal()-5]  = FuzzySet.A_BRAKEHARD;
    rules[FuzzySet.D_VERYCLOSE.ordinal()][FuzzySet.V_FAST.ordinal()-5]      = FuzzySet.A_BRAKEHARD;
    rules[FuzzySet.D_CLOSE.ordinal()]    [FuzzySet.V_VERYFAST.ordinal()-5]  = FuzzySet.A_BRAKEHARD;
    rules[FuzzySet.D_CLOSE.ordinal()]    [FuzzySet.V_FAST.ordinal()-5]      = FuzzySet.A_BRAKEHARD;

    rules[FuzzySet.D_VERYCLOSE.ordinal()][FuzzySet.V_JUSTRIGHT.ordinal()-5] = FuzzySet.A_BRAKE;
    rules[FuzzySet.D_VERYCLOSE.ordinal()][FuzzySet.V_SLOW.ordinal()-5]      = FuzzySet.A_BRAKE;
    rules[FuzzySet.D_CLOSE.ordinal()]    [FuzzySet.V_JUSTRIGHT.ordinal()-5] = FuzzySet.A_BRAKE;
    rules[FuzzySet.D_JUSTRIGHT.ordinal()][FuzzySet.V_VERYFAST.ordinal()-5]  = FuzzySet.A_BRAKE;
    rules[FuzzySet.D_JUSTRIGHT.ordinal()][FuzzySet.V_FAST.ordinal()-5]      = FuzzySet.A_BRAKE;
    rules[FuzzySet.D_FAR.ordinal()]      [FuzzySet.V_VERYFAST.ordinal()-5]  = FuzzySet.A_BRAKE;
    rules[FuzzySet.D_FAR.ordinal()]      [FuzzySet.V_FAST.ordinal()-5]      = FuzzySet.A_BRAKE;
    rules[FuzzySet.D_VERYFAR.ordinal()]  [FuzzySet.V_VERYFAST.ordinal()-5]  = FuzzySet.A_BRAKE;

    rules[FuzzySet.D_VERYCLOSE.ordinal()][FuzzySet.V_VERYSLOW.ordinal()-5]  = FuzzySet.A_NONE;
    rules[FuzzySet.D_CLOSE.ordinal()]    [FuzzySet.V_SLOW.ordinal()-5]      = FuzzySet.A_NONE;
    rules[FuzzySet.D_CLOSE.ordinal()]    [FuzzySet.V_VERYSLOW.ordinal()-5]  = FuzzySet.A_NONE;
    rules[FuzzySet.D_JUSTRIGHT.ordinal()][FuzzySet.V_JUSTRIGHT.ordinal()-5] = FuzzySet.A_NONE;
    rules[FuzzySet.D_VERYFAR.ordinal()]  [FuzzySet.V_FAST.ordinal()-5]      = FuzzySet.A_NONE;
  }

  public FuzzySet useRule(FuzzySet d, FuzzySet v) {
    return rules[d.ordinal()][v.ordinal()-5];
  }
}
